package com.qsw.selectview.test;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.MotionEvent;

import com.qsw.selectview.R;
import com.qsw.selectview.view.OnItemCheckedChangeListener;
import com.qsw.selectview.view.SelectShowMode;
import com.qsw.selectview.view.SelectView;

import java.util.LinkedList;
import java.util.List;

public class SVTestActivity extends Activity {
    private static final String TAG = "TAG_SVTestActivity";

    private SelectView mSv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sv_activity_test);

        mSv = findViewById(R.id.sv_activity_test_testsv);
    }

    @Override
    protected void onResume() {
        show();
        super.onResume();
    }

    private void show() {
        List<String> data = new LinkedList<>();
        data.add("111");
        data.add("22222222");
        data.add("333333");
        data.add("44444");
        data.add("aaaa");
        data.add("55555");
        data.add("6666666666666");
        mSv.setData(data);
        mSv.setMultiSelect(true);
        mSv.setSelectShowMode(SelectShowMode.TEXTBORDER);

        mSv.setOnItemCheckedChangeListener(new OnItemCheckedChangeListener() {
            @Override
            public void onSingleSelectCheckedChange(int checkedItemIndex, String checkedItemStr) {
                Log.d(TAG, checkedItemIndex + " : " + checkedItemStr);
            }

            @Override
            public void onMultiSelectCheckedChange(SparseArray<String> checkedDatas) {
                for (int i = 0; i < checkedDatas.size(); i++) {
                    Log.d(TAG, checkedDatas.keyAt(i) + " : " + checkedDatas.get(checkedDatas.keyAt(i)));
                }
            }
        });
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
//        mSv.removeData("44444");
//        mSv.addData("" + System.currentTimeMillis());

        return super.onTouchEvent(event);
    }
}
